Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

506
Views
¿Cómo usar los atributos [FromBody] y [FromQuery] al mismo tiempo?

En la solicitud de publicación, necesito obtener los parámetros de la cadena de consulta al mismo tiempo. Este es mi código, pero no funciona

 [HttpPost("test")] public string Test(TestRequest request) { //TODO ... } public class TestRequest { [FromHeader(Name = "id")] public string Id { get; set; } [FromQuery(Name = "traceId")] public string Trace { get; set; } public string Name { get; set; } [MaxLength(4)] public string Mark { get; set; } [Range(18, 35)] public int Age { get; set; } }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tienes que poner los diferentes parámetros en el método signatur, entonces sería algo como

 [HttpPost("test/{traceId}")] // Note the query parameter public string Test( [FromHeader(Name = "id")]string id, [FromQuery(Name = "traceId")]string trace, [FromBody]Request request ) { // TODO... } public class Request { public string Name { get; set; } public string Mark { get; set; } public int Age { get; set; } }

bit dependiendo de cómo se vea su solicitud real. Esto leería un Request-Object del cuerpo, el id del encabezado y el traceId de la consulta.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!